package com.zhwmall.member.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhwmall.common.entity.member.MemberEntity;
import com.zhwmall.common.utils.PageUtils;
import com.zhwmall.common.utils.Query;
import com.zhwmall.member.dao.MemberDao;
import com.zhwmall.member.service.MemberService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {


    @Override
    public PageUtils selectPageMember(Map<String, Object> params) {

        String key = (String)params.get("input");

        QueryWrapper<MemberEntity> wrapper = new QueryWrapper<MemberEntity>()
                .like(StringUtils.isNotBlank(key), "username", key)
                .eq(StringUtils.isNotBlank(key),"id", key)
                .eq(StringUtils.isNotBlank(key),"level_id", key)
                .like(StringUtils.isNotBlank(key),"nickname", key)
                .like(StringUtils.isNotBlank(key),"job", key);

        IPage<MemberEntity> page = this.page(
                new Query<MemberEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void removeMemberByIds(List<Long> asList) {
        baseMapper.deleteBatchIds(asList);
    }
}